﻿using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour
{

    //定义跳跃起始的速率
    public float JumpSpeed = 5.0f;

    //跳跃的高度值
    public float JumpHeight = 4.0f;

    public bool IsLanding = false;

    // Use this for initialization
    void Start()
    {
        IsLanding = false;
    }

    // Update is called once per frame
    void Update()
    {
        if (IsLanding)
        {
            if (Input.GetMouseButtonDown(0))
            {
                IsLanding = false;
                float ySpeed = Mathf.Sqrt(2.0f*Mathf.Abs(Physics.gravity.y)*JumpHeight);
                rigidbody.velocity = Vector3.up * ySpeed;
            }
        }
    }

    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag=="Floor")
        {
            IsLanding = true;
        }     
    }
}
